﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;

namespace CC98.Text.UBB.Controls
{
    internal class Container : StackPanel, IElementCollection
    {
        public Container(ITextControlFactory textControlFactory)
        {
            this._textControlFactory = textControlFactory;
            this.Orientation = Windows.UI.Xaml.Controls.Orientation.Vertical;
        }

        public void Add(object elm)
        {
            if (elm == null)
                throw new ArgumentNullException("elm");
            if (elm is UIElement)
                this.Children.Add((UIElement)elm);
            else if (elm is string)
                this.Children.Add(this._textControlFactory.CreateNormalText((string)elm));
            else
                throw new ArgumentException("Not supported element type:" + elm.GetType().FullName);
        }

        private ITextControlFactory _textControlFactory;
    }
}
